//
// Created by francklinson on 2021/11/20 AT 20:07.
// May Saint Diana bless you!
//

#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
    string toHex(int num) {
        if (num == 0) {
            return "0";
        }
        string s;
        for (int i = 7; i >= 0; --i) {
            int val = (num >> (4 * i)) & (0xf);
            if (!s.empty() || val > 0) { // 去除前导0
                char digit = val < 10 ? (char) ('0' + val) : (char) ('a' + val - 10);
                s.push_back(digit);
            }
        }
        return s;
    }
};

int main() {
    Solution solution;
    cout << solution.toHex(26) << endl;
    cout << solution.toHex(-1) << endl;
    return 0;
}

